<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>玉灵 QQ:7031633 Email:webrx@126.com</title>
</head>
<body>
<h1>猜数游戏</h1>
<input type="number" autofocus placeholder="请输入数字">
<button>猜一猜</button>
<button>出题</button>
<p></p>
<script>
    //输出游戏结果
    let pp = document.querySelector('p')
    //获取表单的输入框
    let ii = document.querySelector('input')
    let bs = document.querySelectorAll('button')
    //猜一猜
    let gbtn = bs[0]
    //出题
    let cbtn = bs[1]

    //1-100 随机整数
    var num = Math.round(Math.random() * 99) + 1

    let n = 0
    gbtn.onclick = function(){
        ++n
        if(Number(ii.value)>num){
            pp.innerHTML+=`<p>${n}、太大了(${ii.value})</p>`
        }else if(Number(ii.value)<num){
            pp.innerHTML+=`<p>${n}、太小了(${ii.value})</p>`
        }else{
            pp.innerHTML+=`<p>${n}、恭喜，你猜对了(${ii.value})</p>`
        }
    }

    cbtn.addEventListener('click',function(){
        n = 0
        pp.innerHTML=''
        ii.value = ''
        ii.focus()
        num = Math.round(Math.random() * 99) + 1
        document.title = '出题成功，请猜数！！！'
    })
</script>
</body>
</html>
